package com.net.framework.help.utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import java.util.Timer;
import java.util.TimerTask;

/***
 * 软键盘管理工具类
 * 
 * @author zhangxiaobin
 * 
 */
public class InputMethodUitle {
	static Timer timer = new Timer();
	/***
	 * 隐藏软键盘
	 */
	public static void hideSoftKeyboard(Activity context) {
		View view = context.getWindow().peekDecorView();
        if (view != null) {
            InputMethodManager inputmanger = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
	}

	/***
	 * 显示软键盘
	 */
	public static void showSoftKeyboard(final EditText et) {
		timer.schedule(new TimerTask() {
			public void run() {
				InputMethodManager inputManager = (InputMethodManager) et.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
				inputManager.showSoftInput(et, 0);
			}
		}, 300);
	}

}
